package com.yonyou.train.web;

import com.yonyou.train.ResultJson;
import com.yonyou.train.StatusCode;
import com.yonyou.train.service.ReleaseCourseService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping(value = "/releasecourse")
public class ReleaseCourseController {
    @Autowired
    private ReleaseCourseService releaseCourseService;

    //1.我要开课主页接口
    @RequestMapping(value = "/classes", method = RequestMethod.GET)
    public Object getCreatedClasses(/*@RequestParam(value = "pageindex") int pageindex, @RequestParam(value = "pagesize") int pagesize,*/ HttpServletRequest request) {
        return ResultJson.success(StatusCode.SUCCESS, "success", releaseCourseService.getCreatedClasses(/*pageindex, pagesize, */request.getHeader("token")));
    }

    //2.创建课程接口
    @RequestMapping(value = "/createclass", method = RequestMethod.POST)
    public Object createClass(@RequestBody Map<String, Map<String,Object>> map) {
        releaseCourseService.createClass(map.get("param"));
        return ResultJson.sucs("success");
    }

    //3.搜索人员接口
    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public Object Users(/*@RequestParam(value = "pageindex") int pageindex, @RequestParam(value = "pagesize") int pagesize, */@RequestParam(value = "type") String type,
                        @RequestParam(value = "search") String search) {
        return ResultJson.success(StatusCode.SUCCESS, "success", releaseCourseService.getUsers(/*pageindex, pagesize, */type, search));
    }

    //4.课程详情接口
    @RequestMapping(value = "/classdetails/{classid}", method = RequestMethod.GET)
    public Object getCLassDetails(@PathVariable String classid) {
        return ResultJson.success(StatusCode.SUCCESS, "Success", releaseCourseService.getClassDetails(classid));
    }

    //5.考勤状态接口
    @RequestMapping(value = "/attdetails/{subclassid}", method = RequestMethod.GET)
    public Object getAttDetails(@PathVariable String subclassid) {
        return ResultJson.success(StatusCode.SUCCESS, "Success", releaseCourseService.getAttDetails(subclassid));
    }

    //6.取消子课程接口
    @RequestMapping(value = "/dropsubclass", method = RequestMethod.POST)
    public Object dropSubClass(@RequestBody Map<String, Long> subclassid) {
        releaseCourseService.dropSubClass(subclassid);
        return ResultJson.sucs("success");
    }

    //7.修该课程
    @RequestMapping(value = "/updateclass", method = RequestMethod.POST)
    public Object updateClass(@RequestBody Map<String, Map<String,Object>> map) {
        releaseCourseService.updateClass(map.get("param"));
        return ResultJson.sucs("success");
    }

    //8.查看人员考勤信息和请假信息
    @RequestMapping(value = "/getuserinfo/{subclassid}", method = RequestMethod.GET)
    public Object getUserInfo(@PathVariable String subclassid/*, @RequestParam(value = "pageindex") int pageindex, @RequestParam(value = "pagesize") int pagesize*/, @RequestParam String type, @RequestParam String search) {
        return ResultJson.success(StatusCode.SUCCESS, "success", releaseCourseService.getUserInfo(/*pageindex, pagesize, */subclassid, type, search));
    }

    //9.修改请假状态
    @RequestMapping(value = "/updateleastate", method = RequestMethod.POST)
    public Object updateState(@RequestBody Map<String, Map<String,Object>> map) {
        releaseCourseService.updateLeaState(map.get("param"));
        return ResultJson.sucs("success");
    }

    //10.删除整条课程接口
    @RequestMapping(value = "/dropcourse", method = RequestMethod.POST)
    public Object dropCourse(@RequestBody Map<String, Map<String,Long>> map) {
        releaseCourseService.dropCourse(map.get("param"));
        return ResultJson.sucs("success");
    }
}
